home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Dolphin.lua < prev    next >
Text File  |  2009-12-13  |  4KB  |  134 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Dolphin + Projectile Dolphin
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, December 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.dolphin={}
  10. cc.dolphin.dolphin={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.dolphin.gfx_wpn=loadgfx("weapons/dolphin.bmp")                    -- Weapon Image
  14. setmidhandle(cc.dolphin.gfx_wpn)
  15. cc.dolphin.sfx_attack=loadsfx("dolphin.ogg")                        -- Attack Sound
  16.  
  17. --------------------------------------------------------------------------------
  18. -- Weapon: Dolphin
  19. --------------------------------------------------------------------------------
  20.  
  21. cc.dolphin.id=addweapon("cc.dolphin","Flopper The Dolphin",cc.dolphin.gfx_wpn,0,2)    -- Add Weapon (0 uses, first in round 2)
  22.  
  23. function cc.dolphin.draw()                                                            -- Draw
  24.     -- HUD Positioning
  25.     if weapon_shots==0 then
  26.         hudpositioning(pos_invisible)
  27.         hudinfo("Click to define Flopper's target position!")
  28.     end
  29. end
  30.  
  31. function cc.dolphin.attack(attack)                                    -- Attack
  32.     if (weapon_shots<=0) and (weapon_position==1) then
  33.         -- No more weapon switching!
  34.         useweapon(0)
  35.         playsound(cc.dolphin.sfx_attack)
  36.         playsound(sfx_hitwater4)
  37.         weapon_shots=weapon_shots+1
  38.         -- Find closest player (to determine dolphin jump direction)
  39.         closest=10000
  40.         setdir=1
  41.         players=playertable()
  42.         for i=1,#players,1 do
  43.             if getplayerhealth(players[i])>0 then
  44.                 dist=math.sqrt((weapon_x-getplayerx(players[i]))^2 + (weapon_y-getplayery(players[i]))^2)
  45.                 if dist<closest then
  46.                     closest=dist
  47.                     if getplayerx(players[i])>weapon_x then
  48.                         setdir=1
  49.                     else
  50.                         setdir=-1
  51.                     end
  52.                 end
  53.             end
  54.         end
  55.         -- Create Dolphin
  56.         pid=createprojectile(cc.dolphin.dolphin.id)
  57.         projectiles[pid]={}
  58.         if (setdir==1) then
  59.             projectiles[pid].dir=1
  60.             projectiles[pid].sinus=0
  61.         else
  62.             projectiles[pid].dir=-1
  63.             projectiles[pid].sinus=180        
  64.         end
  65.         projectiles[pid].x=weapon_x-90
  66.         projectiles[pid].y=getwatery()+30
  67.         projectiles[pid].amplitude=(getwatery()+30)-weapon_y
  68.         if (projectiles[pid].amplitude)<100 then
  69.             projectiles[pid].amplitude=100
  70.         end
  71.         if projectiles[pid].amplitude>getmapheight()+50 then
  72.             projectiles[pid].amplitude=getmapheight()+50
  73.         end
  74.         projectiles[pid].speed=500.0/projectiles[pid].amplitude
  75.         projectiles[pid].tx=projectiles[pid].x+projectiles[pid].sinus
  76.         projectiles[pid].ty=projectiles[pid].y
  77.         particle(p_waterhit,projectiles[pid].tx,getwatery()-30)
  78.         -- End Turn
  79.         endturn()
  80.     end
  81. end
  82.  
  83. --------------------------------------------------------------------------------
  84. -- Projectile: Dolphin
  85. --------------------------------------------------------------------------------
  86.  
  87. cc.dolphin.dolphin.id=addprojectile("cc.dolphin.dolphin")        -- Add Projectile
  88.  
  89. function cc.dolphin.dolphin.draw(id)                            -- Draw
  90.     -- Setup draw mode
  91.     setblend(blend_alpha)
  92.     setalpha(1)
  93.     setcolor(255,255,255)
  94.     -- Calculate projectile rotation
  95.     if projectiles[id].dir==1 then
  96.         setscale(1,1)
  97.         setrotation(projectiles[pid].sinus)
  98.     else
  99.         setscale(-1,1)
  100.         setrotation(projectiles[pid].sinus-180)
  101.     end
  102.     -- Draw projectile
  103.     drawimage(cc.dolphin.gfx_wpn,projectiles[id].tx,projectiles[id].ty)
  104. end
  105.  
  106. function cc.dolphin.dolphin.update(id)                                                                            -- Update
  107.     -- Calculate new position
  108.     projectiles[id].sinus=projectiles[id].sinus+projectiles[id].dir*projectiles[pid].speed                        -- Change Sinus
  109.     projectiles[id].tx=projectiles[id].x+projectiles[id].sinus                                                    -- New X (root + sinus)
  110.     projectiles[id].ty=projectiles[id].y-math.sin(math.rad(projectiles[id].sinus))*projectiles[id].amplitude    -- New Y (root + sin(sinus)*amplitude)
  111.     -- Push all close players
  112.     players=playertable()
  113.     for i=1,#players,1 do
  114.         if getplayerhealth(players[i])>0 then
  115.             if math.sqrt((projectiles[id].tx-getplayerx(players[i]))^2 + (projectiles[id].ty-getplayery(players[i]))^2)<50 then
  116.                 playerpush(players[i],projectiles[id].dir*3,-3,1,1)
  117.             end
  118.         end
  119.     end
  120.     -- Free projectile?
  121.     free=0
  122.     if (projectiles[id].dir>0) then
  123.         if (projectiles[id].sinus>180) then free=1 end
  124.     else
  125.         if (projectiles[id].sinus<0) then free=1 end
  126.     end
  127.     if (free==1) then
  128.         freeprojectile(id)
  129.         playsound(sfx_hitwater2)
  130.         particle(p_waterhit,projectiles[id].tx,getwatery()-30)
  131.     end
  132.     -- Scroll to projectile
  133.     scroll(projectiles[id].tx,projectiles[id].ty)
  134. end